import torch
import torch.nn as nn
import pandas as pd
import bpUtils_sse
from env import Creator
creator = Creator() #不用初始化,只调用方法，属于方法工具类，因为是类，所以需要创建实例
_, _, _, car_list_actual = creator.car_list_create()


if __name__ == '__main__':
    #拿到装载序列后做序列分析
    #序列文件
    orders = pd.read_csv("best_orders/CBPDRL/Transformer_SigmoidPG_4Dim_3DBin_actual20230804102835Best_Order.csv") #
    file_name = 'items_data/goods_data_profit_actual_Task7.pt'
    order_numpy = orders['Best_Order'].values
    #print(type(order_tensor.values))
    order_tensor = torch.tensor(order_numpy)
    #货物文件
    items = torch.load(file_name)
    zeros_count = torch.zeros(4)
    for i in items:
        if i[0][5] == 1:
            zeros_count[0] += 1
        if i[0][5] == 2:
            zeros_count[1] += 1
        if i[0][5] == 3:
            zeros_count[2] += 1
        if i[0][5] == 4:
            zeros_count[3] += 1
    print(zeros_count)
    #装箱
    avg_rate, items_list, rate_list, income_list, fl_sum_list = bpUtils_sse.calculate_rate_drl_in_detail_family_orderAnalysis(car_list_actual, items.squeeze(1), torch.tensor(order_numpy).unsqueeze(1))
    #
    for i in fl_sum_list:
        print(i)
    sum_ = torch.zeros((len(items_list)))
    for i in range(len(income_list)):
        for j in income_list[i]:
            sum_[i] += j
    msse = bpUtils_sse.sse_computer(income_list)
    print("income sum:", sum_)
    print("msse:", msse)
    print("ASU:", avg_rate)
    # ordered_items = items[order_tensor]
    # #print(ordered_items[0:5])
    # familis = torch.zeros(ordered_items.shape[0])
    # for i in range(ordered_items.shape[0]):
    #     familis[i] = ordered_items[i][0][5]



